﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using 安检系统.Utils;

namespace 安检系统
{
    /// <summary>
    /// RecordWindow.xaml 的交互逻辑
    /// </summary>
    public partial class RecordWindow : Window
    {
        public String carEffluentStandard = "";
        public RecordWindow()
        {
            InitializeComponent();
        }

        private void queryCar(object sender, RoutedEventArgs e)
        {
            SelectCarDocWindow selectCarDocWindow = new SelectCarDocWindow();
            selectCarDocWindow.Owner = this;
            bool result = (bool)selectCarDocWindow.ShowDialog();
            if (result)
            {
                txtCarNumber.Text = selectCarDocWindow.carNo;
                carEffluentStandard = selectCarDocWindow.carEffluentStandard;
            }
        }

        private void Button_Save_Record(object sender, RoutedEventArgs e)
        {
            String carNo = txtCarNumber.Text.Trim();
            if(carNo.Length == 0)
            {
                MessageBox.Show("请先选择车号");
                return;
            }
            try
            {
                JObject paramJSON = new JObject();
                paramJSON.Add("carNumber", carNo);
                //paramJSON.Add("carEffluentStandard", carEffluentStandard);
                paramJSON.Add("memo", "手工添加");
                String response = HttpPostHelper.doHttpPost("http://192.168.19.220:8000/busParkRecord/add", paramJSON.ToString());

                //String response = HttpPostHelper.doHttpPost("/parkRecord/add", paramJSON.ToString());
                JObject respJson = JObject.Parse(response);
                bool success = (bool)respJson["success"];
                if (success)
                {
                    MessageBox.Show("添加成功");
                    this.DialogResult = true;
                    this.Close();
                }
                else
                {
                    String message = respJson["message"].ToString();
                    MessageBox.Show(message);
                }
            }
            catch (Exception ex) {
                MessageBox.Show("系统错误,请联系管理员");
            }
        }

        private void Button_Click_Close(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
